# Contributor: Fabricio Silva <hi@fabricio.dev>
# Maintainer: Fabricio Silva <hi@fabricio.dev>
pkgname=fnm
pkgver=1.37.2
pkgrel=0
pkgdesc="Fast and simple Node.js version manager, built in Rust"
url="https://github.com/Schniz/fnm"
license="GPL-3.0-or-later"
arch="x86_64" # unofficial does only musl for x86_64
depends="libstdc++" # required for the nodejs
makedepends="cargo cargo-auditable"
checkdepends="bash procps-ng"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
install="$pkgname.post-install"
source="https://github.com/Schniz/fnm/archive/v$pkgver/fnm-$pkgver.tar.gz
	mirror.patch
	musl.patch
	"
options="net" # Required to download Rust crates

export CARGO_PROFILE_RELEASE_OPT_LEVEL="z"

prepare() {
	default_prepare
	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --release --frozen

	for i in bash fish zsh; do
		./target/release/fnm completions --shell $i > fnm-completions.$i
	done
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 target/release/fnm -t "$pkgdir"/usr/bin/

	install -Dm644 fnm-completions.bash "$pkgdir"/usr/share/bash-completion/completions/fnm
	install -Dm644 fnm-completions.fish "$pkgdir"/usr/share/fish/vendor_completions.d/fnm.fish
	install -Dm644 fnm-completions.zsh "$pkgdir"/usr/share/zsh/site-functions/_fnm
}

sha512sums="
8ed1eee4390018be2b29c8e63e3a46e337002403a17e8ad3037aa65ce694875b2bb1e5963258168689ba65b2edfdcf467a9482917857981b2d1c18996fe3c1ff  fnm-1.37.2.tar.gz
b2a33a8a5b0ece33fc560cbef1239817142f0b40acfd41f849e945b92477805bcfb95d3f93b7642138057ea0104ac37989c1120b64a9f6bb7661daa4c7f5fd91  mirror.patch
54a2d359a51e9ed34054f1062ad7fe8abfe5e3f597caf3fca17cc543958dd236e0f2d297541eb78d58ca6ad37e43dac444b673c4aaffee9036ef530cad9bde80  musl.patch
"
